package net.sapfree.display.tags.quan;

import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;

import net.sapfree.common.Constants;
import net.sapfree.core.db.DBConnectionProvider;
import net.sapfree.core.db.Record;

public class MemberTag extends TagSupport {
	private Record r=null;
	private String id=null;
	private static Logger log = Logger.getLogger(MemberTag.class.getClass());
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public int doStartTag() throws JspException {
		System.out.println("perosnuuid is "+id);
		if(id==null||"".equals(id)){//如果id为空，则从quanList中取
			MemberListTag memberList = (MemberListTag) pageContext.getAttribute("MemberListTag");
			r=(Record)memberList.getCurrent();
		}else{
			Connection conn=null;
			
			try {
				conn = DBConnectionProvider.getConnection(Constants.JNDI_SAPFREE);
//				DataBaseExecutor dbe = DataBaseExecutor.getExecutor(conn);
				Record record=new Record(conn,"PERSONINFO");
				record.setPrimaryKey("PI_UUID");
				record.addData("PI_UUID",id); 
				r=record.findByPrimaryKey();
				System.out.println("member info "+r);
				
			} catch (SQLException e) {
				log.error("根据主键查找圈子时出错，",e);
			}finally{
				try{
					 conn.close();
				}catch(Exception e){}
			}
		}
		pageContext.setAttribute("MemberTag", this);
		return EVAL_BODY_INCLUDE;
	}
	
	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}
 
	
	/**
	 * @return the artName
	 */
	public Record getRecord() {
		return r;
	}

	/**
	 * @param artName the artName to set
	 */
	public void setRecord(Record _r) {
		this.r = _r;;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}
}
